package com.senlingspace.web.controller.weixin;

import com.github.pagehelper.PageInfo;
import com.senlingspace.common.constant.HttpStatus;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.core.page.TableDataInfo;
import com.senlingspace.framework.support.WeChatMiniAppPageSupport;
import com.senlingspace.system.domain.vo.ProductResponse;
import com.senlingspace.system.service.ISlkjShopProductService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 小程序商品 API
 *
 * @author lebronjames
 * @date 2024/10/31
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping(path = "/wmp/products/v1")
public class MiniAppProductsController {

    private final ISlkjShopProductService iSlkjShopProductService;


    /**
     * 获取商品类目
     */
    @GetMapping("/types")
    public AjaxResult productTypes() {
        List<ProductResponse> list = iSlkjShopProductService.getWxProductTypes();
        return AjaxResult.success(list);
    }


    /**
     * 小程序商品列表
     */
    @GetMapping("/list")
    public TableDataInfo wxProducts(@RequestParam(required = false) String productName,
                                    @RequestParam(required = false) Long productId,
                                    @RequestParam(required = false) Long productTpyeId) {

        PageInfo<ProductResponse> pageinfo = iSlkjShopProductService.getWxProductsByShopAndName(productName, productTpyeId, productId, WeChatMiniAppPageSupport.getPageNum(), WeChatMiniAppPageSupport.getPageSize());

        TableDataInfo result = new TableDataInfo(pageinfo.getTotal(), pageinfo.getList(), HttpStatus.SUCCESS, "success");

        return result;
    }

}
